﻿/*
 * @autor: hectorea
 * @date: 02/08/12
 * @project: SquareRoot
 * @Reference:
 *  http://www.teacherschoice.com.au/maths_library/trigonometry/triangle_given_3_points.htm
 *  http://www.had2know.com/academics/triangle-area-perimeter-angle-3-coordinates.html
 */

using System;
using System.Drawing;

namespace TriangleGivenThreePoints
{
    class Program
    {
        static void Main(string[] args)
        {
            //Scalene
            //Point A = new Point(1, 3);
            //Point B = new Point(-2, -2);
            //Point C = new Point(3, -1);

            //Isosceles
            //Point A = new Point(0, 0);
            //Point B = new Point(1,1);
            //Point C = new Point(-1, -1);

            //Equilateral
            Point A = new Point(-10, 10);
            Point B = new Point(-1, -1);
            Point C = new Point(10, -10);

            Console.WriteLine("The points corresponds to a {0}", WhichTriagleIs(A, B, C));
            Console.ReadLine();
        }

        /// <summary>
        ///          B
        ///          /\
        ///         /  \
        ///     c  /    \ a
        ///       /      \
        ///      /        \
        ///  A  /_ _ _ _ _ \  C
        ///          b
        /// 
        /// 
        /// </summary>
        /// <param name="p1">Point 1 (A)</param>
        /// <param name="p2">Point 2 (B)</param>
        /// <param name="p3">Point 1 (C)</param>
        /// <returns>The type of triangle based on the given points</returns>
        private static string WhichTriagleIs(Point A, Point B, Point C)
        {
            if (A != B && A != C && B != C)
            {
                double a = GetDistanceBetweenPoints(A, B);
                Console.WriteLine("Side a: {0}", a);
                double b = GetDistanceBetweenPoints(A, C);
                Console.WriteLine("Side b: {0}", b);
                double c = GetDistanceBetweenPoints(B, C);
                Console.WriteLine("Side c: {0}", c);


                if (a != b && a != c && b != c)
                    return "Scalene  Triangle";
                else if ((a == b && a != c) || (a == c && a != b) || (b == c && b != a))
                    return "Isosceles Triangle";
                else if (a == b && a == c)
                    return "Equilateral Triangle";
                else
                    return "Not a Triangle!";
            }
            else
            {
                return "Not a Triangle!";
            }
            
        }

        /// <summary>
        ///        _________________________
        ///       |          2             2
        /// d=  \ | (x2 - x1)  +  (y2 - y1)
        ///      \| 
        /// </summary>
        /// <param name="p1">Point  1</param>
        /// <param name="p2">Point 2</param>
        /// <returns>The distance between the given points</returns>
        private static double GetDistanceBetweenPoints(Point p1, Point p2)
        {
            return Math.Sqrt(((p2.X - p1.X) * (p2.X - p1.X)) + ((p2.Y - p1.Y) * (p2.Y - p1.Y)));

            //double result = ((p2.X - p1.X) * (p2.X - p1.X)) + ((p2.Y - p1.Y) * (p2.Y - p1.Y));
            //return result.SquareRoot();
        }
    }
}
